var gulp = require('gulp')
var glob = require('glob')
var livereload = require('gulp-livereload');
var postcss      = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var plumber = require('gulp-plumber');
var gutil = require('gulp-util');
var less = require('gulp-less')
var path = require('path')

var lessPath = './less'
gulp.task('less4watch',function(){
    var files = glob.sync(lessPath+'/**/*_build.less');
    var dirs = [lessPath];
    for(var i in files){
        dirs.push(path.dirname(files[i]))
    }
    return gulp.src(files,{base:lessPath})
        .pipe(plumber())
        .pipe(less({
            paths:dirs
        }))
        //.pipe(rename(function(path){
        //    path.basename='build';
        //}))
        .pipe(gulp.dest('./build_css'))
        .pipe(livereload())
})

gulp.task('watch',function(){
    livereload.listen();
    return gulp.watch(lessPath+'/**/*.less',['less4watch'])
})